﻿/**
 * Peter
 * Created by: Peter Development Team
 *    http://peter.codeplex.com/
 * 
 * GNU General Public License version 2 (GPLv2)
 *    http://peter.codeplex.com/license
 *
 *  This code is provided on an AS IS basis, with no WARRANTIES,
 *  CONDITIONS or GUARANTEES of any kind.
 *
 **/

using System;
using ICSharpCode.SharpZipLib.Zip;

namespace Peter.Logic
{
   /// <summary>
   /// Represents a zip item for the zip explorer.
   /// </summary>
   public class ModelZipItem
   {
      /// <summary>
      /// Initializes a new zip item.
      /// </summary>
      /// <param name="entry">Zip entry data.</param>
      public ModelZipItem (ZipEntry entry)
      {
         this.ZipObject = entry;
         var zipFile = entry.Name.Split (new [] {'/'}, StringSplitOptions.RemoveEmptyEntries);
         this.FileName = zipFile [zipFile.Length - 1];
         this.DirPath = (zipFile.Length > 1)
            ? entry.Name.Substring (0, entry.Name.LastIndexOf ('/'))
            : "root";
         this.CompressedSize = entry.CompressedSize;
         this.RealSize = entry.Size;
         this.CompressionMethod = entry.CompressionMethod;
         this.Comment = entry.Comment ?? string.Empty;
      }

      /// <summary>
      /// Gets the zip item;s compression method.
      /// </summary>
      public CompressionMethod CompressionMethod { get; private set; }

      /// <summary>
      /// Gets or Sets additional data for this object.
      /// </summary>
      public object ZipObject { get; private set; }

      /// <summary>
      /// Get the zip item's file name.
      /// </summary>
      public string FileName { get; private set; }

      /// <summary>
      /// Get the zip item's comment.
      /// </summary>
      public string Comment { get; private set; }

      /// <summary>
      /// Gets the directory path of the zip item.
      /// </summary>
      public string DirPath { get; private set; }

      /// <summary>
      /// Gets the compressed file size
      /// </summary>
      public double CompressedSize { get; private set; }

      /// <summary>
      /// Gets the uncompressed file size.
      /// </summary>
      public double RealSize { get; private set; }
   }
}
